<template>
  <div>
    <button @click="chanageStyle">显示/隐藏</button>
    <!-- appera属性时一上来就播放一次动画 -->
    <transition name="hello" appear>
      <h1 v-show="isShow">你好啊!</h1>
    </transition>
  </div>
</template>

<script>
export default {
  name: 'Test',
  data() {
    return {
      isShow: true,
    };
  },
  methods: {
    chanageStyle() {
      this.isShow = !this.isShow;
    },
  },
};
</script>

<style scoped>
/* 动画效果实现 */
h1 {
  background-color: orange;
}
/* 播放动画的名字要有规则, transition标签的name-enter-active*/
.hello-enter-active {
  animation: change 0.5s;
}
.hello-leave-active {
  animation: change 0.5s reverse;
}

@keyframes change {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0px);
  }
}
</style>
